package com.sm.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sm.dao.HappyRequestMapper;
import com.sm.model.HappyRequest;
import com.sm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HappyRequestService {

    @Autowired
    private HappyRequestMapper happyRequestMapper;

    /**
     *  新增幸福问答问题接口
     */
    public int insertRequest(HappyRequest happyRequest){
        int i = happyRequestMapper.insertRequest(happyRequest);
        return i;
    }

    /**
     *  拉取幸福问答问题列表
     */
    public PageResult selectHapptyRequestList(Integer currentPage, Integer pageSize){
        PageHelper.startPage(currentPage, pageSize);
        Page<HappyRequest> happyRequestPage = happyRequestMapper.selectHapptyRequestList();
        return new PageResult(happyRequestPage.getTotal(),happyRequestPage.getResult());
    }

    /**
     * 幸福问答--我的提问列表
     */
    public PageResult myRequest(Integer currentPage,Integer pageSize,Integer userId){
        PageHelper.startPage(currentPage,pageSize);
        Page<HappyRequest> happyRequests = happyRequestMapper.selectByUserId(userId);
        return new PageResult(happyRequests.getTotal(),happyRequests.getResult());
    }


    /**
     * 拉取幸福问答问题详情
     */
    public HappyRequest selectRequestById(Integer requestId){
        return happyRequestMapper.selectRequestById(requestId);
    }

    /**
     * 修改幸福问答问题
     */
    public Integer update(HappyRequest happyRequest){
        return happyRequestMapper.update(happyRequest);
    }

    /**
     * 获取幸福问答精品列表
     */
    public List<HappyRequest> getBotiqueList(Integer limit){
        return happyRequestMapper.getBotiqueList(limit);
    }
}
